home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SpriteEngine
/
SE Gravity FixedPoint
/
SpriteHanders.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-11
|
2KB
|
65 lines
#include "SpriteTools.h"
// SpriteTools.h includes SpriteHandlers.h
/*** Custom handlers - application dependent ***
Edit this as necessary. It should always include the following three routines:
MoveSprite: move the sprite
HitSprite: handle collisions between two sprites
InitSprites: Load all faces and create initial sprites
***/
GrafPtr firstFace, secondFace, thirdFace;
void MoveSprite(SpritePtr theSprite)
{
theSprite->speed.v++; // Simple gravity
theSprite->fixedPointPosition.h += theSprite->speed.h;
theSprite->fixedPointPosition.v += theSprite->speed.v;
theSprite->position.h = theSprite->fixedPointPosition.h >> 4;
theSprite->position.v = theSprite->fixedPointPosition.v >> 4;
KeepOnScreenFixed(theSprite);
} /*MoveSprite*/
void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
{
// No collision handling in this demo!
} /*HitSprite*/
void InitSprites()
{
SpritePtr theSprite;
/*Load all pictures*/
firstFace = LoadFaceFromCicn(128); /*cicn resource #128.*/
secondFace = LoadFaceFromCicn(129); /*cicn resource #129.*/
thirdFace = LoadFaceFromCicn(130); /*cicn resource #130.*/
/*Create sprites*/
theSprite = NewSprite();
theSprite->face = firstFace;
SetPt(&theSprite->fixedPointPosition, 100 << 4, 100 << 4);
SetPt(&theSprite->speed, 1, 16);
theSprite = NewSprite();
theSprite->face = secondFace;
SetPt(&theSprite->fixedPointPosition, 50 << 4, 50 << 4);
SetPt(&theSprite->speed, 16, 1);
theSprite = NewSprite();
theSprite->face = thirdFace;
SetPt(&theSprite->fixedPointPosition, 150 << 4, 150 << 4);
SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
} /*InitSprites*/